using MyStatus;
using Services;
using System.Collections.Generic;
using UnityEngine;

public class HUD_StatusBar : MonoBehaviour
{
    private Player player;
    private StatusIcon[] icons;

    private void Start()
    {
        player = ServiceLocator.Get<ActionController>().player;
        icons = GetComponentsInChildren<StatusIcon>();
        player.StatusChange += SetIcons;
        SetIcons();
    }

    public void SetIcons()
    {
        LinkedList<RuntimeStatus> statusList = player.StatusManager.GetStatus();
        int count = 0;
        foreach (RuntimeStatus status in statusList)
            if (count < icons.Length)
                icons[count++].SetStatus(status);
        for (; count < icons.Length;)
            icons[count++].SetStatus(null);
    }
}
